package com.toocms.jinjuhang.ui.mine.involved_result

import android.graphics.Typeface
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.StyleSpan
import com.google.android.material.tabs.TabLayout
import com.toocms.jinjuhang.R
import com.toocms.jinjuhang.BR
import com.toocms.jinjuhang.databinding.FgtInvolvedResultBinding
import com.toocms.jinjuhang.ui.base.BaseFgt

class InvolvedResultFgt : BaseFgt<FgtInvolvedResultBinding, InvolvedResultModel>() {
    override fun onFragmentCreated() {
        topBar.setTitle(R.string.str_involved_result)
        binding.filterTl.apply {
            addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
                override fun onTabSelected(tab: TabLayout.Tab?) {
                    tab?.apply {
                        val titleSpan = SpannableStringBuilder(text.toString())
                        titleSpan.setSpan(
                            StyleSpan(Typeface.BOLD),
                            0,
                            titleSpan.length,
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                        )
                        text = titleSpan
                    }

                }

                override fun onTabUnselected(tab: TabLayout.Tab?) {
                    tab?.apply {
                        text = text.toString()
                    }
                }

                override fun onTabReselected(tab: TabLayout.Tab?) {

                }

            })
            addTab(
                newTab().setText(R.string.str_all)
                    .setTag(InvolvedResultStatus.ALL)
            )
            addTab(
                newTab().setText(R.string.str_check_pending)
                    .setTag(InvolvedResultStatus.CHECK_PENDING)
            )
            addTab(
                newTab().setText(R.string.str_already_passed)
                    .setTag(InvolvedResultStatus.ALREADY_PASSED)
            )
            addTab(
                newTab().setText(R.string.str_not_pass)
                    .setTag(InvolvedResultStatus.NOT_PASS)
            )
        }
    }

    override fun getLayoutResId() = R.layout.fgt_involved_result

    override fun getVariableId() = BR.involvedResultModel

    override fun viewObserver() {

    }
}